package arrAndstr;

/*
    222. 完全二叉树的节点个数
 */
public class T222 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public int countNodes(TreeNode root) {
        return DLR(root);
    }

    private int DLR(TreeNode root) {
        if (root == null)   return 0;

        return 1 + DLR(root.left) + DLR(root.right);
    }


}
